//时间戳转日期对象
export const formatDate = (timestamp, format) => {
	// 将时间戳转换为日期对象
	const date = new Date(timestamp);
	const year = date.getFullYear();
	const month = date.getMonth() + 1;
	const day = date.getDate();
	const hours = date.getHours();
	const minutes = date.getMinutes();
	const seconds = date.getSeconds();

	// 替换需要的时间格式
	format = format.replace('yyyy', year);
	format = format.replace('MM', month < 10 ? '0' + month : month);
	format = format.replace('dd', day < 10 ? '0' + day : day);
	format = format.replace('HH', hours < 10 ? '0' + hours : hours);
	format = format.replace('mm', minutes < 10 ? '0' + minutes : minutes);
	return format;
}

// 顶部安全距离
export function getSafeArea() {
	const systemInfo = uni.getSystemInfoSync();
	let statusBarHeight = 0;
	let navBarHeight = 44; // 默认导航栏高度

	// #ifdef MP-WEIXIN
	// 微信小程序获取胶囊按钮位置信息
	const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
	statusBarHeight = systemInfo.statusBarHeight || 0;
	navBarHeight = (menuButtonInfo.top - statusBarHeight) * 2 + menuButtonInfo.height;
	// #endif

	// #ifdef H5
	statusBarHeight = 0; // H5通常不需要状态栏高度
	navBarHeight = 44; // H5导航栏高度
	// #endif

	return {
		statusBarHeight,
		navBarHeight,
		safeAreaTop: statusBarHeight + navBarHeight
	};
}